import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class PropertiesUtil {
	private ObjectInputStream ois = null;
	private ObjectOutputStream oos = null;
	private List<User> lstUsers = new ArrayList<User>();
	
	public PropertiesUtil(String fileName){
		try {
			ois = new ObjectInputStream(new FileInputStream(fileName));
			oos = new ObjectOutputStream(new FileOutputStream("config/temp.dat"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}   
	}
	
	@SuppressWarnings("unchecked")
	public  List<User> getUsers(){
		try {
			lstUsers =  (ArrayList<User>)ois.readObject();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		try {
			ois.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return lstUsers;
   }
	
	public void save(User user){
		try {
			lstUsers.add(user);
			oos.writeObject(lstUsers);
			oos.flush();
			oos.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
